<script setup>
import useStore from '../store';
const { todos } = useStore()
console.log('todos', todos);
const changeAll = (e) => {
  console.log('e', e.target.checked);
  todos.changeAll(e.target.checked)
}

// 数据持久化
todos.$subscribe(() => {
  localStorage.setItem('todos', JSON.stringify(todos.list))
})
</script>

<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" :checked="todos.isCheckAll" @change="changeAll($event)" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li :class="{ completed: item.done }" v-for="item in todos.showList" :key="item.id">
        <div class="view">
          <input class="toggle" type="checkbox" :checked="item.done" @change="todos.changeDone(item.id)" />
          <label>{{ item.name }}</label>
          <button class="destroy" @click="todos.del(item.id)"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
    </ul>
  </section>
</template>

<style lang="less" scoped>
</style>
